package com.lzm.ydpt.mvp.presenterimpl;

import com.byt.framlib.basemvp.BasePresenter;
import com.byt.framlib.basemvp.basebean.BaseResponseBean;
import com.byt.framlib.basemvp.basebean.ListPageBean;
import com.byt.framlib.basemvp.boby.FormBodys;
import com.byt.framlib.basemvp.exception.ApiException;
import com.byt.framlib.basemvp.listener.OnLoadingErrorListener;
import com.byt.framlib.basemvp.listener.OnLoadingProgressListener;
import com.lzm.ydpt.entity.mall.ShopInfoBean;
import com.lzm.ydpt.module.mall.fragment.ShopListFragment;
import com.lzm.ydpt.mvp.api.ProgressSubscriber;
import com.lzm.ydpt.mvp.contract.ShopListContract;
import com.lzm.ydpt.mvp.modelimpl.ShopListModelImpl;

/**
 * 类名称：MyXhXnPresenterImpl
 * 类描述：代理实现
 */
public class ShopListPresenterImpl extends BasePresenter implements ShopListContract.Presenter {

    private ShopListContract.View mView;
    private ShopListContract.Model mModel;

    public ShopListPresenterImpl(ShopListFragment context) {
        super(context.getActivity());
        this.mView = context;
        this.mModel = new ShopListModelImpl();
    }

    @Override
    public void onFetchShopList(FormBodys formBodys) {
        mManager.http(mModel.onFetchShopList(formBodys), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<ListPageBean<ShopInfoBean>>() {
            @Override
            public void onLoadingResult(BaseResponseBean<ListPageBean<ShopInfoBean>> entity) {
                mView.onFetchShopList(entity.getData());
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showErrorView(e.getDisplayMessage());
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showErrorView(entity.getMessage());
            }
        }, "onFetchShopList"));
    }
}